<?php
$loader->requireOnce('includes/inPatientCore/InPatientCoreErrorCode.class.php');
$loader->requireOnce('includes/inPatientCore/InPatientCoreException.class.php');
$loader->requireOnce('includes/EnumerationConstant.class.php');
$loader->requireOnce('includes/EmerQueueFactory.class.php');
$loader->requireOnce('includes/EmergencyInstantPanel.class.php');

$loader->requireOnce('includes/EmerProcessor.class.php');



/**
 * Controler for processing emergency instant panel. 
 * @package module.dept_emer.controllers
 * @author viethd
 * @version $Id$
 * @copyright 2009 LHV Company
 */
class C_PatientInfo extends Controller {
	private $logger ;
	private $tpProcessor ;
	function __construct($template_mod = "general") {
		parent::Controller();		
		$this->logger = LoggerManager::getLogger('module.dept_emer.controllers.C_PatientInfo');
		$this->template_mod = $template_mod;
		$this->view->path="patient_instant_info";
		$this->tpProcessor = new EmerProcessor($this);
	}
	/**
	 * Build instant info panel.
	 * @param $_GET['ticketId']
	 * @return jsonObject instant info panel.
	 */
	public function actionInstantInfoAjax() {
		$ticketId = $_GET['ticketId'];
		$instantPanel = new EmergencyInstantPanel($ticketId);
		$result = $instantPanel->renderPanel();
		return json_encode($result);
	}
	/**
	 * Build patient info form.
	 * @param $_GET['ticketId']
	 * @return jsonObject patient info.
	 */
	public function actionLoadPatientInfoAjax() {
		$result = array('error'=>array('code'=>0,'mess'=>''));
        $ticketId = $_GET['ticketId'];
        
        $this->logger->info('Start load patient info for patient has ticket ['. $tickId .']');
        try {
        	
            $result['result'] = $this->tpProcessor->loadIPPatientInfo($ticketId); 
           
        } catch (InpatientCoreException $ex) {
        	 
            $result['error']['code'] = $ex->getErrorCode();
            $result['error']['mess'] = InPatientCoreErrorCode::getErrorMess($ex->getErrorCode());
            $this->logger->error('Load patient info for ticket [' . $tickId . '] fail. Error detail: '. $ex->getMessage());
        } 
        $this->logger->info('Finish load patient info for patient has ticket ['. $tickId .']');
        return json_encode($result);
	}

}
?>